<?php 
class Web extends CI_Controller{

	function __construct(){

		parent::__construct();
		$this->load->model('web_model');
		$this->load->helper('share');
		$this->load->library('pagination');
	}
	
	public function index(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		$table = $this->web_model->getAllBerita();

		$config['uri_segment'] = 3;
		$config['total_rows'] = count($table);
		$config['per_page'] = $per_page = 3;
		$config['base_url'] = base_url();
		$this->pagination->initialize($config);

		$data['berita'] = $this->web_model->getBeritaByPage($per_page, ($this->uri->segment(3) ? $this->uri->segment(3) : 0));
		$data['pagination'] = $this->pagination->create_links();


		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/content', $data);
		$this->load->view('web/right_sidebar', $data);
		$this->load->view('web/footer');
	}

	function agenda(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		$table = $this->web_model->getAllAgenda();

		$config['uri_segment'] = 3;
		$config['total_rows'] = count($table);
		$config['per_page'] = $per_page = 2;
		$config['base_url'] = base_url()."web/agenda";
		$config['full_tag_open'] = "<ul class='pagination'>";
		$config['full_tag_close'] ="</ul>";
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li>";
		$config['next_tagl_close'] = "</li>";
		$config['prev_tag_open'] = "<li>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li>";
		$config['last_tagl_close'] = "</li>";

		$this->pagination->initialize($config);

		$data['agenda'] = $this->web_model->getAgendaByPage($per_page, ($this->uri->segment(3) ? $this->uri->segment(3) : 0));
		$data['pagination'] = $this->pagination->create_links();


		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/agenda', $data);
		$this->load->view('web/footer');
	}

	function jaringan_elearning(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/jaringan_elearning', $data);
		$this->load->view('web/footer');
	}

	function desktop_elearning(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/desktop_elearning', $data);
		$this->load->view('web/footer');
	}

	function web_elearning(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/web_elearning', $data);
		$this->load->view('web/footer');
	}


	function hardware_elearning(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/hardware_elearning', $data);
		$this->load->view('web/footer');
	}


	function berita(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		$table = $this->web_model->getAllBerita();

		$config['uri_segment'] = 3;
		$config['total_rows'] = count($table);
		$config['per_page'] = $per_page = 3;
		$config['base_url'] = base_url();
		$this->pagination->initialize($config);

		$data['berita'] = $this->web_model->getBeritaByPage($per_page, ($this->uri->segment(3) ? $this->uri->segment(3) : 0));
		$data['pagination'] = $this->pagination->create_links();


		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/content', $data);
		$this->load->view('web/right_sidebar', $data);
		$this->load->view('web/footer');
	}


	function detailberita(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['detail'] = $this->web_model->getDetailBerita($id);
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/detail_berita', $data);
		$this->load->view('web/footer');
	}

	function detailagenda(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['detail'] = $this->web_model->getDetailAgenda($id);
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/detail_agenda', $data);
		$this->load->view('web/footer');
	}

	function detailinfo(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['detail'] = $this->web_model->getDetailInfo($id);
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/detail_info', $data);
		$this->load->view('web/footer');
	}

	function profil(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/profil', $data);
		$this->load->view('web/footer');
	}

	function visimisi(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/visimisi', $data);
		$this->load->view('web/footer');
	}

	function denah(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/denah', $data);
		$this->load->view('web/footer');
	}

	function struktur(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi_desktop'] = $this->web_model->getElearningDesktop();
		$data['materi_web'] = $this->web_model->getElearningWeb();
		$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
		$data['materi_hardware'] = $this->web_model->getElearningHardware();
		
		$this->load->view('web/header', $data);
		$this->load->view('web/left_sidebar', $data);
		$this->load->view('web/struktur', $data);
		$this->load->view('web/footer');
	}


	function download(){
		$file = $this->uri->segment(3);
		$data = file_get_contents("./image/materi/".$file); // Read the file's contents
		$name = $file;
		force_download($name, $data);
	}

	function member(){

		if($this->session->userdata('is_login')){
			$this->load->model('member');

			$data['info'] = $this->web_model->getAllInfo();
			$data['materi_desktop'] = $this->web_model->getElearningDesktop();
			$data['materi_web'] = $this->web_model->getElearningWeb();
			$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
			$data['materi_hardware'] = $this->web_model->getElearningHardware();
			
			$data['materi'] = $this->web_model->getElearning();
			$data['divisi'] = $this->web_model->getDivisi();
			
			$this->load->view('web/header', $data);
			$this->load->view('web/left_sidebar', $data);
			$this->load->view('member/member', $data);
			$this->load->view('web/footer');

		} else {
			redirect('web/restricted');
		}
	}


function edit_member(){
	$this->output->enable_profiler(TRUE);
		if($this->session->userdata('is_login')){
					$posting = $this->input->post('submit');
					if($posting){
						$this->load->model('member');
						$this->load->library('form_validation');

						$this->form_validation->set_rules('nama_lengkap', 'NAMA LENGKAP', 'required');
						$this->form_validation->set_rules('pwd', 'Password', 'required');
						$this->form_validation->set_rules('nama_panggilan', 'NAMA PANGGILAN', 'required');
						$this->form_validation->set_rules('no_telp', 'NOMOR TELEPON', 'required');
						$this->form_validation->set_rules('email', 'EMAIL', 'required');
						$this->form_validation->set_rules('alamat', 'ALAMAT', 'required');

						if ($this->form_validation->run() == FALSE){
							$data ['error'] = validation_errors ();
						}else{
									$NIM = $this->session->userdata('NIM');
									$pwd = $this->input->post('pwd');
									$nama_lengkap = $this->input->post('nama_lengkap');
									$telp = $this->input->post('no_telp');
									$email = $this->input->post('email');
									$alamat = $this->input->post('alamat');


									$ubah = $this->member->updateMember($NIM, $nama_lengkap, $nama_lengkap, $alamat, $telp, $email, $pwd);

									if($ubah){
											$NIM = $this->input->post('NIM');
											//$userData = $this->member->getDetailMember($NIM);
											$sessionData['nama'] =  $this->input->post('nama_lengkap');
											$sessionData['password'] = $pwd = $this->input->post('pwd');
											$sessionData['email'] = $this->input->post('email');
											$sessionData['telp'] = $this->input->post('no_telp');
											$sessionData['alamat'] = $this->input->post('alamat');
											$this->session->set_userdata($sessionData);
											
											redirect('web/member');
									}else{
											$data['error']   = "Error Mengubah Data";
									}

						}
					
					}else{

						$data['error'] = $this->session->flashdata('error');			
					}	

				$this->load->model('member');

				$data['info'] = $this->web_model->getAllInfo();
				$data['materi_desktop'] = $this->web_model->getElearningDesktop();
				$data['materi_web'] = $this->web_model->getElearningWeb();
				$data['materi_jaringan'] = $this->web_model->getElearningJaringan();
				$data['materi_hardware'] = $this->web_model->getElearningHardware();
				
				$data['materi'] = $this->web_model->getElearning();
				$data['divisi'] = $this->web_model->getDivisi();
				
				$this->load->view('web/header', $data);
				$this->load->view('web/left_sidebar', $data);
				$this->load->view('member/editmember', $data);
				$this->load->view('web/footer');

				
		} else {
			redirect('web/restricted');
		}

}
	


	function login_validation(){
		$this->load->model('member');
		$this->load->library('form_validation');
		$this->form_validation->set_rules('NIM', "NIM", 'required|callback_validate_credentials');
		$this->form_validation->set_rules('password', "Password", 'required');

		if($this->form_validation->run()==true){
			$NIM = $this ->input->post('NIM');
			$password = $this->input->post('password');
			$userData = $this->member->cek_member_login($NIM,$password);
			if(!empty($userData)){
				//$sessionData['id'] = $userData['id'];
				$sessionData['id'] = $userData['id'];
				$sessionData['nama'] = $userData['nama'];
				$sessionData['NIM'] = $userData['NIM'];
				$sessionData['divisi'] = $userData['divisi'];
				$sessionData['email'] = $userData['email'];
				$sessionData['hp'] = $userData['hp'];
				$sessionData['alamat'] = $userData['alamat'];
				$sessionData['asal_sekolah'] = $userData['asal_sekolah'];
				$sessionData['is_login'] = TRUE;

				$this->session->set_userdata($sessionData);
				//echo "berhasil";
				redirect('web/member');
				//$this->load->view('admin/dashboard/index');
			}else{
				$this->session->set_flashdata('Login Failed!, email and password combination was wrong ');
				//echo "gagal";
				redirect('web');
			}
		}
	}

	function restricted(){
		$this->load->view('restricted');
	}

	function logout(){
		$this->session->sess_destroy();
		redirect("web");
	}

	function not_found(){

		$this->load->view('404');
	}

}

 ?>